import { StoreEdgeItemType } from '../workflow/edge';
import { FlowNodeTemplateType, StoreNodeItemType } from '../workflow/node';

import { PluginSourceEnum, PluginTypeEnum } from './constants';

export type PluginItemSchema = {
  _id: string;
  userId: string;
  teamId: string;
  tmbId: string;
  name: string;
  avatar: string;
  intro: string;
  updateTime: Date;
  modules: StoreNodeItemType[];
  edges: StoreEdgeItemType[];
  parentId: string;
  type: `${PluginTypeEnum}`;
  metadata?: {
    pluginUid?: string;
    apiSchemaStr?: string;
    customHeaders?: string;
  };
  version?: 'v1' | 'v2';
  nodeVersion?: string;
  inited?: boolean;
};

/* plugin template */
export type PluginTemplateType = PluginRuntimeType & {
  author?: string;
  id: string;
  source: PluginSourceEnum;
  templateType: FlowNodeTemplateType['templateType'];
  intro: string;
  version: string;
};

export type PluginRuntimeType = {
  teamId?: string;
  name: string;
  avatar: string;
  showStatus?: boolean;
  isTool?: boolean;
  nodes: StoreNodeItemType[];
  edges: StoreEdgeItemType[];
};

export type PluginItem = {
  app_id: string;
  app_name: string;
  app_logo: string;
  scene_image: string;
  app_description: string;
  review_status: string;
  group_name: string;
  user_name: string;
  create_time: string;
  app_type: string;
  app_template_type: string;
  app_workbench_type: string;
  review_description: string;
  templateUsageCount: number;
  templateThumbUpCount: number;
  templateThumbDownCount: number;
  isCollect: boolean;
  isSSO: boolean;
  roles_for_user_in_app: string[];
  share_id: string;
  createUserId: string;
};
